﻿/*
Copyright 2010 Matías Fidemraizer (www.matiasfidemraizer.com).

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

using System;
using Comkarl.Architecture.Patterns.DomainModel;
using Comkarl.Architecture.Patterns.MVC.Entities;
using Comkarl;

namespace PAISA.PDA.Business.Domains.Common.Actions
{
    /// <summary>
    /// Represents an MVC action performed within an domain (DDD).
    /// </summary>
    /// <typeparam name="TDomainObjectIdentifierName">
    /// The type for domain object identifier's name.
    /// </typeparam>
    /// <typeparam name="TDomainObject">
    /// The type for domain object.
    /// </typeparam>
    public abstract class DomainAction<TDomainObjectIdentifierName, TDomainObject> : Comkarl.Architecture.Patterns.MVC.Entities.Action<TDomainObjectIdentifierName>, IHierarchyTopMostParentIdentifiable
        where TDomainObjectIdentifierName : IEquatable<TDomainObjectIdentifierName>
        where TDomainObject : DomainObject<TDomainObjectIdentifierName>
    {
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="associatedObject">
        /// An associated domain object with this action.
        /// </param>
        public DomainAction(ActionIdentifier<TDomainObjectIdentifierName> id, TDomainObject associatedObject)
            : base(id)
        {
            this.associatedObject = associatedObject;
        }

        private readonly TDomainObject associatedObject;

        /// <summary>
        /// The associated domain object with this action.
        /// </summary>
        public TDomainObject AssociatedObject
        {
            get
            {
                return associatedObject;
            }
        }

        /// <summary>
        /// Gets the base type for this action.
        /// </summary>
        public virtual Type TopMostParentType
        {
            get
            {
                return typeof(DomainAction<TDomainObjectIdentifierName, TDomainObject>);
            }
        }
    }
}